using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BuildTool : MonoBehaviour
{
    [SerializeField] Transform pos0;
    [SerializeField] Transform pos1;
    [SerializeField] GameObject mPrefab;

    [ContextMenu("Build")]
    void BuildLine()
    {
        var p0 = pos0.position;
        var p1 = pos1.position;
        if (p0.x == p1.x)
        {
            var step = p1.y - p0.y;
            var gap = step < 0 ? -1 : 1;
            step = Mathf.Abs(step);
            for (var i = 0; i <= step; i++)
            {
                GameObject.Instantiate(mPrefab,new Vector3(p0.x, p0.y+i*gap,0f),Quaternion.identity);
            }
        }
        else if (p0.y == p1.y)
        {
            var step = p1.x - p0.x;
            var gap = step<0 ? -1 : 1;
            step = Mathf.Abs(step);
            for (var i = 0; i <= step; i++)
            {
                GameObject.Instantiate(mPrefab, new Vector3(p0.x + i * gap, p0.y, 0f), Quaternion.identity);
            }
        }
    }
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }
}
